//////////////////////////////////////////////////////////////////////////////
//
//  Created by Philip Mulcahy on 27/09/2012.
//  Copyright (c) 2012 Philip Mulcahy. All rights reserved.
//
//  This file is part of the note-recog library.
//
//  note-recog is free software: you can redistribute it and/or modify
//  it under the terms of version 3 of the GNU Lesser General Public License 
//  as published by the Free Software Foundation.
//
//  note-recog is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with note-recog. If not, see <http://www.gnu.org/licenses/>.
//
//////////////////////////////////////////////////////////////////////////////

#include "Frame.h"
#include "Spectrum.h"

std::ostream& operator<<(std::ostream& os, const Frame& frame)
{
    return os << "Frame{ts=" << frame.startTimestamp() << ",rms=" << frame.spectrum().rms() << "}";
}

std::vector<Frame> Frame::halves() const
{
    const size_t child_size = _time_domain.size()/2;
    const TimeDomain first(
        _time_domain.begin(),
        _time_domain.begin()+child_size);
    const TimeDomain second(
        _time_domain.begin()+child_size,
        _time_domain.end());
    
    std::vector<Frame> results;
    
    const float child_duration = _time_domain.size()/_spectrum.samplingFreq()/2.f;
    
    results.push_back(Frame(
        first,
        _timestamp,
        _spectrum.samplingFreq()));
    results.push_back(Frame(
        second,
        _timestamp + child_duration,
        _spectrum.samplingFreq()));
    
    return results;
}